﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

public class SelectModeView : IUIView
{
    int index=0, oldIndex = 0;
    public Button  normal_btn,difficult_btn,back;
    public override void Initinalize()
    {
        index = oldIndex = 0;
        back.onClick.AddListener(Return);
        normal_btn.onClick.AddListener(()=> { SetMode(GameMode.Normal); });
        difficult_btn.onClick.AddListener(()=> { SetMode(GameMode.Difficult); });

    }
    void SetMode(GameMode mode)
    {
        GameManager.Instance.gameMode = mode;
    }

    private void Update()
    {
        if (Input.GetKeyDown(KeyCode.DownArrow))
        {
            if (index == 2) return;
            oldIndex = index;
            index++;
            index = Mathf.Clamp(index, 0, 2);
            OnPointerChange(oldIndex, index);
        }
        else if (Input.GetKeyDown(KeyCode.UpArrow))
        {
            if (index == 0) return;
            oldIndex = index;
            index--;
            index = Mathf.Clamp(index, 0, 2);
            OnPointerChange(oldIndex, index);
        }
        else if (Input.GetKeyDown(KeyCode.Return))
        {
            switch (index)
            {
                case 0:
                    SetMode(GameMode.Normal);
                    break;
                case 1:
                    SetMode(GameMode.Difficult);
                    break;
                case 2:
                    Return();
                    break;
            }
        }
    }
    void Return()
    {
        Hide(); UIManager.Instance.mainPanel.Show();
    }
    void OnPointerChange(int oldIndex,int index)
    {
        switch (oldIndex)
        {
            case 0:
                normal_btn.transform.GetChild(0).gameObject.SetActive(false);
                break;
            case 1:
                difficult_btn.transform.GetChild(0).gameObject.SetActive(false);
                break;
            case 2:
                back.transform.GetChild(0).gameObject.SetActive(false);
                break;
        }
        switch (index)
        {
            case 0:
                normal_btn.transform.GetChild(0).gameObject.SetActive(true);
                break;
            case 1:
                difficult_btn.transform.GetChild(0).gameObject.SetActive(true);
                break;
            case 2:
                back.transform.GetChild(0).gameObject.SetActive(true);
                break;
        }
    }
    public override void Hide()
    {
        base.Hide();

    }
    public override void Show()
    {
        base.Show();
    }
}
